package com.back.mapper;

import com.back.entity.Review;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ReviewDao {
    // 获取某个电影的评论，带分页，按时间排序
    @Select("select * from review where movie_id = #{movie_id} order by date desc limit #{offset}, #{pagesize}")
    List<Review> selectReviewByMovieId(@Param("movie_id") int movie_id, @Param("offset") int offset,@Param("pagesize") int pagesize);

    // 获取某个电影的评论数量
    @Select("select count(*) from review where movie_id = #{movie_id}")
    int selectReviewCountByMovieId(@Param("movie_id") int movie_id);

    // 对某个电影添加评论
    @Select("insert into review(movie_id, from_user_id, content, date) values(#{movie_id}, #{from_user_id}, #{content}, #{date})")
    void insertReview(Review review);

}
